package com.chatim.nonamechatim.netty.common;

import com.alibaba.fastjson2.JSON;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

import static java.time.LocalDateTime.now;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class WSRes {

    private Integer code;

    private Long fid;

    private String msg;

    private LocalDateTime time;

    /**
     * 信息失败响应提示
     */
    public static TextWebSocketFrame fail(String msg){
        return new TextWebSocketFrame(JSON.toJSONString(new WSRes(1001, 0L, msg, now())));
    }

    public static TextWebSocketFrame success(String msg){
        return new TextWebSocketFrame(JSON.toJSONString(new WSRes(1002, 0L, msg, now())));
    }

    public static TextWebSocketFrame success(Long fid, String msg, LocalDateTime time){
        return new TextWebSocketFrame(JSON.toJSONString(new WSRes(1002, fid, msg, time)));
    }
}
